﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace ebc.componentbinder.tests
{
    [TestFixture]
    public class test_CompileEventDefinedByType
    {
        [Test]
        public void Type_with_no_events()
        {
            Assert.AreEqual(0, ComponentBinder.CompileEventsPublishedBy(new NoEvents()).Count());
        }

        [Test]
        public void Type_with_relevant_events()
        {
            var edList = ComponentBinder.CompileEventsPublishedBy(new OnlyRelevantEvents());
            Assert.AreEqual(3, edList.Count());
        }

        [Test]
        public void Ignores_irrelevant_events()
        {
            var edList = ComponentBinder.CompileEventsPublishedBy(new SomeRelevantEvents());
            Assert.AreEqual(1, edList.Count());
            Assert.AreEqual("Double", edList.First().PinName);
        }

        [Test]
        public void Ignores_non_public_events()
        {
            var edList = ComponentBinder.CompileEventsPublishedBy(new NonPublicEvents());
            Assert.AreEqual(0, edList.Count());
        }

        [Test]
        public void Find_events_in_base_classes()
        {
            var edList = ComponentBinder.CompileEventsPublishedBy(new DerivedWithRelevantEvents());
            Assert.That(edList.Select(e => e.PinName).ToArray(), Is.EquivalentTo(new[]{"String", "Double"}));
        }
    }
}
